'libtgfx - Threaded Graphics library for FreeBASIC
'Copyright (C) 2013  Ebben Feagan <sir@mud.owlbox.net>
'
'This library is free software; you can redistribute it and/or
'modify it under the terms of the GNU Lesser General Public
'License as published by the Free Software Foundation; either
'version 2.1 of the License, or (at your option) any later version.
'
'This library is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
'Lesser General Public License for more details.
'
'You should have received a copy of the GNU Lesser General Public
'License along with this library; if not, write to the Free Software
'Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include once "tgfx.bi"
#include once "tgfx-priv.bi"

namespace tgfx.mouse

    sub get(    byref x as integer, _
                byref y as integer, _
                byref wheel as integer, _
                byref btns as integer, _
                byref clip as integer _
            ) export

        var cc = new CommChannel()
        Comm->send(new Message(_MMSGET,0,cc))
        var ret = cc->recv()
        while ret = 0
            ret = cc->recv()
            sleep 1,1
        wend
        var i = cast(line_data ptr,ret->x->d)
        x = i->f.x
        y = i->f.y
        wheel = i->s.x
        btns = i->s.y
        clip = *(cast(integer ptr,@(i->c)))
        delete cc
        delete ret

    end sub

    sub set(    byval x as integer = -1, _
                byval y as integer = -1, _
                byval visible as integer = -1, _
                byval clip as integer = -1 _
            ) export

        Comm->send(new Message(_MMSSET,new MData(new line_data(0,Coord(x,y),Coord(visible,clip),0,tgfx.false,tgfx.false),@null_free)))

    end sub

end namespace
